<?php 

require _DIR_ . '/wsysphp/base.php';

if(!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}

$argv = $_SERVER['argv'];
array_shift($argv);

$commandPath = _DIR_ . DS . 'wsysphp' . DS . 'command' . DS;

function console($text, $pre = "\n") {
    echo $pre."$text\n";
}

if(!empty($argv)) {
    $command = strtolower($argv[0]);
    array_shift($argv);

    switch($command) {
        case '-v': case '--version':
            console("v" . MVERSION);
        break;
        case '-h': case '--help': case 'help':
            require_once $commandPath . 'help.php';
        break;
        default:
            $commandPath .= $command . '.php';
            if(!is_file($commandPath)) {
                console("命令：" . $command . " 不存在");
                return;
            }
            require_once $commandPath;
            exit;
    }

} else {
    require_once $commandPath . 'help.php';
}
